import service from '@/utils/request'
import qs from 'qs';
import { getRefreshToken } from '@/utils/auth'
//账密登录
export const passLoginRequest = data => {
  return service({
    method: 'post',
    url: '/login',
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    data: qs.stringify(data)
  })
}

export const phoneLoginRequest = data => {
  return service({
    method: 'post',
    url: '/sys/login',
    data
  })
}

//注册获取验证码
export const getVerificationRequest = data => {
  return service({
    method: 'post',
    url: '/register/getValidCode',
    data
  })
}

// //校验验证码
// export const checkVerificationRequest = params => {
//   return service({
//     method: 'post',
//     url: `/register/checkValidCode/${params.mobilePhone}/${params.validCode}`,
//   })
// }

//提交注册
export const submitRegisterRequest = data => {
  return service({
    method: 'post',
    url: '/register/submitRegister',
    data
  })
}

//手机号登录获取验证码
export const getVerificationPhoneRequest = data => {
  return service({
    method: 'post',
    url: '/userLogin/getLoginValidCode',
    data
  })
}

//手机号登录
export const submitSMSLoginRequest = data => {
  return service({
    method: 'post',
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    url: '/smsLogin',
    data: qs.stringify(data)
  })
}

//退出登录
export const logoutRequest = data => {
  return service({
    method: 'get',
    url: '/logout',
  })
}

//无感刷新token
export const refreshTokenRequest = () => {
  return service({
    method: 'post',
    url: '/refreshToken',
    headers: { 
      Authorization: getRefreshToken() 
    },
  })
}

//找回密码获取验证码
export const retrieveCodeRequest = data => {
  return service({
    method: 'post',
    url: '/userLogin/getModifyPasswordValidCode',
    data
  })
}

//找回密码
export const changePasswordRequest = data => {
  return service({
    method: 'post',
    url: '/userLogin/findBackPassword',
    data
  })
}

//测试请求
export const testRequest = () => {
  return service({
    method: 'get',
    url: '/personCenter/test',
  })
}

//微信扫码登录
export const getWeChatRequest = params => {
  return service({
    method: 'get',
    url: '/weixinLogin',
    params
  })
}

//获取微信扫码配置
export const getWeChatConfigRequest = () => {
  return service({
    method: 'get',
    url: '/userLogin/getWeixinLoginConfig',
  })
}
